package com.sqsf.text;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidPooledConnection;
import com.mchange.v2.c3p0.ComboPooledDataSource;
import com.sqsf.javabean.User;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;

import java.sql.Connection;
import java.sql.SQLException;

@RunWith(SpringRunner.class)//将当前测试类标记为spring运行测试类
@ContextConfiguration("classpath:spring.xml")//读取配置文件 创建spring容器
public class SpringTest {
    //之前需要通过getbean获取 并强转才能使用的对象
    //直接声明对应类型变量 书写注解 会自动获取注入
    @Autowired
    DruidDataSource druid;
    @Autowired
    ComboPooledDataSource c3p0;
    @Autowired
    User u1;
    @Test
    public void u1() throws SQLException {
        System.out.println(u1);
    }
    @Test
    public void c3p0() throws SQLException {
        Connection connection = c3p0.getConnection();
        System.out.println(connection);
        connection.close();
    }
    @Test
    public void druid() throws SQLException {
        DruidPooledConnection connection = druid.getConnection();
        System.out.println(connection);
        connection.close();
    }
}
